package org.jpush.core;

import org.jpush.core.socket.JPushClientSocket;

public abstract class AbstractAcceptor
{
	private Listener listener;
	private int listeningPort;

	protected Server server;
	protected ListenerOptions options;

	public AbstractAcceptor(Server server)
	{
		if (server == null)
		{
			throw new IllegalArgumentException("Server Cannot be null");
		}
	    this.server = server;
	    this.listener = new Listener(this);
	    this.listeningPort = 0;
	    
	    // Create options
	    this.options = new ListenerOptions();
	    options.setProtocol(server.getProtocol());
	}
	
	public Server getServer()
	{
		return this.server;
	}

	public void setListeningPort(int port)
	{
	    this.listeningPort = port;
	}
	
	public int getListeningPort()
	{
		return this.listeningPort;
	}

	public boolean startListening()
	{
	    return listener.startListening();
	}

	public void stopListening()
	{
	    listener.stopListening();
	}

	public ListenerOptions getOptions()
	{
	    return options;
	}

	public void setOptions(ListenerOptions options)
	{
	    this.options = options;
	}

	protected abstract boolean handleAcceptedSocket(JPushClientSocket clientSocket);
}
